/**
*      author: Y_Yao
*      created: 2025-03-27 17:02:00
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 200 + 7;
bool dp[N][N][5];
int a[5];
unordered_map<char,int> mp;
bool ok[N][N][5];

void solve()
{
    mp['W'] = 1,mp['I'] = 2,mp['N'] = 3,mp['G'] = 4;
    for(int i = 1;i <= 4;i++) cin >> a[i];
    for(int i = 1;i <= 4;i++)
    {
        for(int j = 1;j <= a[i];j++)
        {
            string s;
            cin >> s;
            ok[mp[s[0]]][mp[s[1]]][i] = true;
        }
    }

    string s;
    cin >> s;
    int n = s.size();
    s = " " + s;
    for(int i = 1;i <= n;i++)
    {
        dp[i][i][mp[s[i]]] = true;
    }
    for(int len = 1;len <= n;len++)
    {
        for(int i = 1;i + len <= n;i++)
        {
            int j = i + len;
            for(int k = i;k < j;k++)
            {
                for(int x = 1;x <= 4;x++)
                {
                    for(int y = 1;y <= 4;y++)
                    {
                        for(int z = 1;z <= 4;z++)
                        {
                            if(dp[i][k][y] && dp[k+1][j][z] && ok[y][z][x])
                            {
                                dp[i][j][x] = true;
                            }
                        }
                    }
                }
            }
        }
    }

    int f = 0;
    if(dp[1][n][1]) f = 1,cout << 'W';
    if(dp[1][n][2]) f = 1,cout << 'I';
    if(dp[1][n][3]) f = 1,cout << 'N';
    if(dp[1][n][4]) f = 1,cout << 'G';
    if(f == 0)
    {
        cout << "The name is wrong!" << endl;
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}